// 认证状态管理
const Auth = {
    isLoggedIn: function() {
        return localStorage.getItem('isLoggedIn') === 'true' && 
               localStorage.getItem('userId') !== null;
    },
    
    checkAuth: function() {
        if (!this.isLoggedIn()) {
            console.warn('未登录或会话过期');
            sessionStorage.setItem('redirectUrl', window.location.pathname);
            window.location.href = 'login.html';
            return false;
        }
        return localStorage.getItem('userId');
    },
    
    clearAuth: function() {
        ['isLoggedIn', 'userId', 'userBasic'].forEach(key => {
            localStorage.removeItem(key);
        });
    },
    
    getCurrentUserId: function() {
        return this.checkAuth(); // 返回userId或false
    }
};